package pers.karl.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pers.karl.module.entity.TestEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * @author karl
 * @description: ${description}
 * @create 2019-01-20 16:38
 */
@Controller
@RequestMapping("test")
public class TestController {

    private Logger logger = LoggerFactory.getLogger(TestController.class);

    @ResponseBody
    @RequestMapping("log")
    public Map log(String value) {
        logger.debug("测试中文");

        logger.debug("test log request param: {}", value);
        logger.info("test log request param: {}", value);
        logger.warn("test log request param: {}", value);

        try{
            double b = 0.00;
            double df = Double.valueOf(value) / b;
            System.out.println(df);
        } catch (Exception e) {
            logger.error("测试错误", e);
        }

        Map<String,Object> map = new HashMap<>(1);
        map.put("param", value);
        return map;
    }

    @ResponseBody
    @RequestMapping("json")
    public TestEntity jsonParam(@RequestBody TestEntity testEntity) {
        return testEntity;
    }

}
